<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Weighdata extends Model
{
    protected $table = 'weightdata';

    protected $primaryKey = 'system_number';

    protected $keyType = 'string';

    protected $fillable = [
    	'system_number',
        'order_systemnumber',
        'vehicle_type',
        'isGoogs',
        'io_status',
    	'system_datetime',
    	'process_number',
    	'trans_type',
    	'trans_status',
    	'vehicle_number',
    	'is_finished',
    	'site_code',
    	'first_readic_datetime',
    	'second_readic_datetime',
    	'ic_id',
        'empty_weight',
        'is_empty',
    	'first_status',
    	'first_time',
    	'first_weight',
    	'first_wbid',
    	'second_status',
    	'second_weight',
    	'second_time',
    	'second_wbid',
    	'net_weight',
    	'actual_weight',
    	'weight_error',
    	'weight_error_ratio',
        'empty_weight_time',
        'is_success',
    	'first_capvh_path',
    	'first_capvh_filename',
    	'first_capvn_path',
    	'first_capvn_filename',
    	'first_capvn',
    	'second_capvh_path',
    	'second_capvh_filename',
    	'second_capvn_path',
    	'second_capvn_filename',
    	'second_capvn',
    	'first_cap_a_path',
    	'first_cap_a_fielname',
    	'first_cap_b_path',
    	'first_cap_b_fielname',
    	'second_cap_a_path',
    	'second_cap_a_fielname',
    	'second_cap_b_path',
    	'second_cap_b_fielname',
    	'remarks'
    ];

    protected $appends = [
        'process_number_desc',
        'trans_type_desc',
        'trans_status_desc',
        'is_finished_desc',
        'first_status_desc',
        'second_status_desc',
        'is_success_desc',
        'vehicle_type_desc',
        'isGoogs_desc',
        'io_status_desc'
    ];

    const PROCESS_NUMBER_SALE = 'SALE';

    const PROCESS_NUMBER_PURCHASE = 'PURCHASE';

    public static $PROCESS_NUMBER = [
        self::PROCESS_NUMBER_SALE => '提货',
        self::PROCESS_NUMBER_PURCHASE => '送货'
    ];

    const TRANS_TYPE_WA = 'WA';

    const TRANS_TYPE_CT = 'CT';

    public static $TRANS_TYPE = [
        self::TRANS_TYPE_WA => '正常',
        self::TRANS_TYPE_CT => '作废'
    ];

    const TRANS_STATUS_A = 'A';

    const TRANS_STATUS_C = 'C';

    const TRANS_STATUS_NT = 'NT';

    public static $TRANS_STATUS = [
        self::TRANS_STATUS_A => '修改',
        self::TRANS_STATUS_C => '被作废',
        self::TRANS_STATUS_NT => '正常'
    ];

    const IS_FINISHED_YES = 'Y';

    const IS_FINISHED_NO = 'N';

    public static $IS_FINISHED = [
        self::IS_FINISHED_YES => '是',
        self::IS_FINISHED_NO => '否'
    ];


    const IS_SUCCESS_YES = 'Y';

    const IS_SUCCESS_NO = 'N';

    public static $IS_SUCCESS = [
        self::IS_SUCCESS_YES => '出厂过磅成功',
        self::IS_SUCCESS_NO => '出厂过磅失败'
    ];

    const WEIGHT_STATUS_AUTO = 'AUTO';

    const WEIGHT_STATUS_MANU = 'MANU';

    public static $WEIGHT_STATUS = [
        self::WEIGHT_STATUS_AUTO => '自动',
        self::WEIGHT_STATUS_MANU => '人工'
    ];

    const VEHICLE_TYPE_EX = 'EX';

    const VEHICLE_TYPE_IN = 'IN';

    public static $VEHICLE_TYPE = [
        self::VEHICLE_TYPE_EX => '外部车辆',
        self::VEHICLE_TYPE_IN => '内部车辆'
    ];


    const ISGOOGS_YES = 'Y';

    const ISGOOGS_NO = 'N';

    public static $ISGOOGS = [
        self::ISGOOGS_YES => '是',
        self::ISGOOGS_NO => '否'
    ];

    const IO_STATUS_ZERO = '0';

    const IO_STATUS_ONE = '1';

    public static $IO_STATUS = [
        self::IO_STATUS_ZERO => '进厂',
        self::IO_STATUS_ONE => '出厂'
    ];

    public function getVehicleTypeDescAttribute(){
        if(array_key_exists('vehicle_type', $this->attributes) && $this->attributes['vehicle_type'] != null){
            return $this->attributes['vehicle_type_desc'] = self::$VEHICLE_TYPE[$this->attributes['vehicle_type']];
        }
    }

    public function getIsGoogsDescAttribute(){
        if(array_key_exists('isGoogs', $this->attributes) && $this->attributes['isGoogs'] != null){
            return $this->attributes['isGoogs_desc'] = self::$ISGOOGS[$this->attributes['isGoogs']];
        }
    }

    public function getIoStatusDescAttribute(){
        if(array_key_exists('io_status', $this->attributes) && $this->attributes['io_status'] != null){
            return $this->attributes['io_status_desc'] = self::$IO_STATUS[$this->attributes['io_status']];
        }
    }

    public function getProcessNumberDescAttribute(){
        if(array_key_exists('process_number', $this->attributes) && $this->attributes['process_number'] != null){
            return $this->attributes['process_number_desc'] = self::$PROCESS_NUMBER[$this->attributes['process_number']];
        }
    }

    public function getTransTypeDescAttribute(){
        if(array_key_exists('trans_type', $this->attributes) && $this->attributes['trans_type'] != null){
            return $this->attributes['trans_type_desc'] = self::$TRANS_TYPE[$this->attributes['trans_type']];
        }
    }

    public function getTransStatusDescAttribute(){
        if(array_key_exists('trans_status', $this->attributes) && $this->attributes['trans_status'] != null){
            return $this->attributes['trans_status_desc'] = self::$TRANS_STATUS[$this->attributes['trans_status']];
        }
    }

    public function getIsFinishedDescAttribute(){
        if(array_key_exists('is_finished', $this->attributes) && $this->attributes['is_finished'] != null){
            return $this->attributes['is_finished_desc'] = self::$IS_FINISHED[$this->attributes['is_finished']];
        }
    }

    public function getFirstStatusDescAttribute(){
        if(array_key_exists('first_status', $this->attributes) && $this->attributes['first_status'] != null){
            return $this->attributes['first_status_desc'] = self::$WEIGHT_STATUS[$this->attributes['first_status']];
        }
    }

    public function getSecondStatusDescAttribute(){
        if(array_key_exists('second_status', $this->attributes) && $this->attributes['second_status'] != null){
            return $this->attributes['second_status_desc'] = self::$WEIGHT_STATUS[$this->attributes['second_status']];
        }
    }

    public function getIsSuccessDescAttribute(){
        if(array_key_exists('is_success', $this->attributes) && $this->attributes['is_success'] != null){
            return $this->attributes['is_success_desc'] = self::$IS_SUCCESS[$this->attributes['is_success']];
        }
    }


    public function internalVehicle(){
        return $this->hasOne('\App\Models\InternalVehicle','ic_id','ic_id');
    }

    public function flowInside(){
        return $this->hasOne('\App\Models\FlowInside','order_systemnumber','order_systemnumber');
    }

}
